dojo.declare("DVendorItemProductCatalogPg", wm.Page, {
    start: function() {

    },
    "preferredDevice": "desktop",

    itemsDojoGridImageUrlFormat: function(inValue, rowId, cellId, cellField, cellObj, rowObj) {
        try {
            var file = "services/FileUploadDownload.download?method=downloadFile&fileName=" + inValue;
            return '<img  style="height: 50px;" src="' + inValue + '" />';
        } catch (e) {
            console.error('ERROR IN dojoGrid2PicurlFormat: ' + e);
        }
    },

    lvVendorsSuccess: function(inSender, inDeprecated) {
        var item = this.selectMenu1.dataSet.getItem(0);
        this.selectMenu1.setDataValue(item);
        
    },
    itemsNewButtonClick1: function(inSender) {
        this.dojoFileUpload1.reset();
        this.itemsDojoGrid.deselectAll();
        this.dojoFileUpload1.reset();
        var item = this.selectMenu1.selectedItem;
        this.lookup1.setDataValue(item);
        
        var result = this.itemsDojoGrid.getRowCount();
        if(result > 0)
        {
            var VAT =  this.itemsDojoGrid.getCell(result - 1,"vat");
            var EduCess =  this.itemsDojoGrid.getCell(result - 1,"eduCess");
            var ServiceTax =  this.itemsDojoGrid.getCell(result - 1,"serviceTax");
            var ServiceCharge =  this.itemsDojoGrid.getCell(result - 1,"serviceCharge");
            var TpsShareIncPer =  this.itemsDojoGrid.getCell(result - 1,"tpsPercentIncl");
            var TpsShareExclPer =  this.itemsDojoGrid.getCell(result - 1,"tpsPercentExl");
            var TpsShareIncl =  this.itemsDojoGrid.getCell(result - 1,"tpsShareIncl");
            var TpsShareExcl =  this.itemsDojoGrid.getCell(result - 1,"tpsShareExl");
            var unit =  this.itemsDojoGrid.getCell(result - 1,"unit");
            var services =  this.itemsDojoGrid.getCell(result - 1,"services.serviceName");
            var currency =  this.itemsDojoGrid.getCell(result - 1,"currency");
            
    	this.txtVAT.setDataValue(VAT);
		this.txtEduCess.setDataValue(EduCess);
		this.txtServiceTax.setDataValue(ServiceTax);
		this.txtServiceCharge.setDataValue(ServiceCharge);
		this.txtTpsShareIncPer.setDataValue(TpsShareIncPer);
		this.txtTpsShareExclPer.setDataValue(TpsShareExclPer);
		this.txtTpsShareIncl.setDataValue(TpsShareIncl);
		this.txtTpsShareExcl.setDataValue(TpsShareExcl);
        this.activeEditor1.setChecked(true);
         var item = this.selectMenu2.dataSet.getItem(0);
        this.selectMenu2.setDataValue("Food");
        this.selectMenu3.setDataValue(unit);
        this.lookup2.setDataValue(services);    
        this.otherNamesEditor3.setDataValue(currency)
        }
        // this.itemsLiveForm1.clearData();
    },
    calculateFinalprice: function() {
     
        var vatPercent = this.txtVAT.getDataValue();
        var eduCess = this.txtEduCess.getDataValue();
        var serviceTax = this.txtServiceTax.getDataValue();
        var serviceCharge = this.txtServiceCharge.getDataValue();
        var tpsPercInc = this.txtTpsShareIncPer.getDataValue();
        var tpsPerExcl = this.txtTpsShareExclPer.getDataValue();
        var tpsShareInc = this.txtTpsShareIncl.getDataValue();
        var tpsShareExcl = this.txtTpsShareExcl.getDataValue();
        var basePrice = this.txtBasePrice.getDataValue();
        var finalPrice = 0;
    
        if (vatPercent != 0) {
            finalPrice = finalPrice + ((vatPercent / 100) * basePrice);
            if (eduCess != 0) {
                var eduCessPercent = vatPercent / eduCess;
                finalPrice = finalPrice + (eduCessPercent / 100) * basePrice;
            }
    
    
        }
        if (serviceTax != 0) {
            finalPrice = finalPrice + (serviceTax / 100) * basePrice;
        }
        if (serviceCharge != 0) {
            finalPrice = finalPrice + (serviceCharge / 100) * basePrice;
        }
        //if (tpsPercInc != 0) {
        //finalPrice  = finalPrice + (tpsPercInc / 100) * basePrice;
        //}
        //else
        if (tpsPerExcl != 0) {
    
            finalPrice = finalPrice + (tpsPerExcl / 100) * basePrice;
        }
        // else if (tpsShareInc != 0) {
        ///  finalPrice  = finalPrice + 
        //}
        else if (tpsShareExcl != 0) {
            tpsShareExcl = tpsShareExcl / 1;
            finalPrice = finalPrice + tpsShareExcl;
        }
    
        basePrice = basePrice / 1;
        finalPrice = finalPrice + basePrice; /* */
        this.priceEditor1.setDataValue(finalPrice);
    
    },
    itemsSaveButtonClick: function(inSender) {
        this.calculateFinalprice();

        this.itemsLiveForm1.saveDataIfValid();
    },
    txtVATChange: function(inSender, inDisplayValue, inDataValue, inSetByCode) {
        this.calculateFinalprice();
    },
    txtServiceTaxChange: function(inSender, inDisplayValue, inDataValue, inSetByCode) {
        this.calculateFinalprice();
    },
    txtVATEnterKeyPress: function(inSender) {
        this.calculateFinalprice();
    },
    txtServiceTaxEnterKeyPress: function(inSender) {
        this.calculateFinalprice();
    },
    txtEduCessChange: function(inSender, inDisplayValue, inDataValue, inSetByCode) {
        this.calculateFinalprice();
    },
    txtServiceChargeChange: function(inSender, inDisplayValue, inDataValue, inSetByCode) {
        this.calculateFinalprice();
    },
    txtBasePriceChange: function(inSender, inDisplayValue, inDataValue, inSetByCode) {
        this.calculateFinalprice();
    },
    txtTpsShareIncPerChange: function(inSender, inDisplayValue, inDataValue, inSetByCode) {
        this.calculateFinalprice();
    },
    txtTpsShareExclPerChange: function(inSender, inDisplayValue, inDataValue, inSetByCode) {
        this.calculateFinalprice();
    },
    txtTpsShareInclChange: function(inSender, inDisplayValue, inDataValue, inSetByCode) {
        this.calculateFinalprice();
    },
    txtTpsShareExclChange: function(inSender, inDisplayValue, inDataValue, inSetByCode) {
        this.calculateFinalprice();
    },
    itemsDojoGridSelect: function(inSender) {
		
	},
	_end: 0
});